home *** CD-ROM | disk | FTP | other *** search
- #define C
-
- #undef PROFILE
- #define COUNT
-
- #include "view.h"
- #include "trig.h"
-
- #ifdef __GNUC__
- #include <osbind.h>
- #include <memory.h>
- #else
- #include <tos.h>
- #endif
-
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
-
- #define SKY_COLOR 1
- #define FLOOR_COLOR 2
- #define WALL_COLOR 3
- #define RED_COLOR 4
- #define LEDGE_COLOR 5
- #define ZMIN 20L
-
- #define UPPER_TYPE 0
- #define WALL_TYPE 1
- #define LOWER_TYPE 2
-
- extern short width;
- extern short height;
-
- extern short flooropt;
- extern short floorcol;
- extern short nofloor;
- extern short wallopt;
- extern short wallcol;
- extern short singlestep;
- extern short showdata;
-
- #ifdef COUNT
- extern long drawview;
-
- extern long addfloor;
- extern long addfloor_loops;
-
- extern long addwall;
- extern long addwall_loops;
-
- extern long coldraw;
- extern long coldraw_loops;
-
- extern long rowdraw;
- extern long rowdraw_loops;
-
- extern long drawnode;
- extern long drawssector;
- extern long drawssector_loops;
- extern long loadseg;
- extern long loadseg_loops1;
- extern long loadseg_loops2;
-
- extern long setuptime;
- extern long drawtime;
- extern long c2ptime;
- #endif
-
- /* Elements of this array indicate if a screen column is completely drawn. */
-
- #if 0
- extern short Col_Done[320];
- #endif
- extern char Col_Done[320]; /* Slightly better for the cache */
-
-
- /* Elements of this array hold indexes into the wall_run array. */
-
- #if 1
- extern short intersections[50][320];
- #endif
-
- /* The number of wall_runs visible on a particular screen column. */
-
- #if 1
- extern short int_count[320];
- #endif
-
- /* MaxY & MinY are the active edge lists for the top & bottom of the screen. */
-
- extern short MaxY[320];
- extern short MinY[320];
-
-
- /* This is the wall_run array. It contains all of the wall_runs which
- * are visible in a single frame.
- */
-
- #if 1
- extern wall_run walls[8000]; /* 320*50 = 16000 */
- #endif
-
- extern short walltop[320];
- extern short wallbottom[320];
-
- /* The next two arrays are used for both floors and ceilings.
- * Elements of this array hold indexes into the floor_run array.
- */
-
- #if 1
- extern floor_run floorlist[200][40];
- #endif
-
- extern short floorlst[200];
- extern short floortex[200];
-
- /* The number of floor_runs visible on a particular screen column. */
-
- extern short runcount[200];
-
-
- /* The offscreen buffer. */
- extern char *screenbuf;
-
-
- extern void c2p(char *buf, int w_area, int h_area);
- extern char hash(side *ThisSide, int wall_type);
- extern long get_timer(void);
-
- /* This function draws a single color column into the
- * offscreen buffer.
- */
-
- void ColDraw(short x, short top, short bottom, char color)
- {
- short y;
- char *pixel;
-
- if (top < 0)
- top = 0;
-
- if (bottom > height)
- bottom = height;
-
- #ifdef COUNT
- coldraw++;
- coldraw_loops += bottom - top;
- #endif
-
- #ifdef __GNUC__
- #if 0
- pixel = &screenbuf[(long)((top << 6) + (top << 8)) + x];
- #else
- pixel = &screenbuf[(long)top * width + x];
- #endif
- #else
- #if 0
- pixel = &(((short *)screenbuf)[(((long)top << 6) + ((long)top << 8)) >> 1]);
- #else
- pixel = &(((short *)screenbuf)[((long)top * width) >> 1]);
- #endif
- pixel += x;
- #endif
- #if 0
- for (short y = top;y < bottom;y++) {
- #endif
- for(y = bottom - top - 1;y >= 0;y--) {
- *pixel = color;
- pixel += width;
- }
- }
-
-
- /* This function draws a single color row into the
- * offscreen buffer.
- */
-
- void RowDraw(short y, short left, short right, char color)
- {
- short x;
- char *pixel;
-
- if (left < 0)
- left = 0;
-
- if (right > width)
- right = width;
-
- #ifdef COUNT
- rowdraw++;
- rowdraw_loops += right - left;
- #endif
-
- #ifdef __GNUC__
- #if 0
- pixel = &screenbuf[(long)((y << 6) + (y << 8)) + left];
- #else
- pixel = &screenbuf[(long)y * width + left];
- #endif
- #else
- #if 0
- pixel = &(((short *)screenbuf)[(((long)y << 6) + ((long)y << 8)) >> 1]);
- #else
- pixel = &(((short *)screenbuf)[((long)y * width) >> 1]);
- #endif
- pixel += left;
- #endif
- #if 0
- for (short x = left;x < right;x++) {
- #endif
- for(x = right - left - 1;x >= 0;x--) {
- if (!singlestep) {
- *pixel = color;
- } else {
- *pixel ^= color; /* EXOR */
- }
- pixel++;
- }
- }
-
- /* Here is where we blast all of the runs to the screen buffer. */
-
- void DrawSegs(void)
- {
- short row;
- char ch = 0;
- short run;
- short x, i;
- short Wall;
- wall_run *ThisWallRun;
-
- #if 0
- if (nofloor && !flooropt) {
- memset(screenbuf, 0, (long)width * height);
- }
- #endif
-
- if (!flooropt && !nofloor) {
- for(row = 0;row < height / 2;row++) {
- for(run = 0;run < runcount[row];run++) {
- if (!floorcol) {
- RowDraw(row, floorlist[row][run].start,
- floorlist[row][run].end, SKY_COLOR);
- } else {
- RowDraw(row, floorlist[row][run].start,
- floorlist[row][run].end, floorlist[row][run].tex_num);
- }
- if (singlestep && (ch != 's')) {
- c2p(screenbuf, width, height);
- ch = Cnecin();
- }
- }
- if (singlestep) {
- c2p(screenbuf, width, height);
- ch = Cnecin();
- }
- }
-
- for (row = height / 2;row < height;row++) {
- for(run = 0;run < runcount[row];run++) {
- if (!floorcol) {
- RowDraw(row, floorlist[row][run].start,
- floorlist[row][run].end, FLOOR_COLOR);
- } else {
- RowDraw(row, floorlist[row][run].start,
- floorlist[row][run].end, floorlist[row][run].tex_num);
- }
- }
- if (singlestep && (ch != 's')) {
- c2p(screenbuf, width, height);
- ch = Cnecin();
- }
- }
- if (singlestep) {
- c2p(screenbuf, width, height);
- ch = Cnecin();
- }
- }
- if (!wallopt) {
- for(x = 0;x < width;x++)
- for(i = 0;i < int_count[x];i++) {
- Wall = intersections[i][x];
- ThisWallRun = &walls[Wall];
- ColDraw(x, ThisWallRun->top, ThisWallRun->bottom,
- (char)ThisWallRun->tex_num);
- }
- }
- }
-